// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store/index'
import $http from './request/index'
import methodsInjection from '@/utils/methodInjection.js'
import 'lib-flexible'
import {
  Swipe,
  SwipeItem,
  Popup,
  InfiniteScroll,
  Picker 
} from 'mint-ui';

Vue.component(Swipe.name, Swipe);
Vue.component(SwipeItem.name, SwipeItem);
Vue.component(Popup.name, Popup);
Vue.use(InfiniteScroll);
Vue.component(Picker.name, Picker);

Vue.config.productionTip = false
$http.defaults.withCredentials = true;
Vue.prototype.$http = $http
methodsInjection()
router.beforeEach((to, from, next) => {
  if (to.meta.token && store.state.users.isLogin === false  ) {
    next({
      name: "Login",
      params: {
        edirect: to.path
      }
    })
  } else {
    next()
  }
  // if(to.fullPath == "/login"){
  //   if(localStorage.getItem('token')){
  //     next({
  //       path:from.fullPath
  //     });
  //   }else {
  //     next();
  //   }
  // }
}),


/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {
    App
  },
  template: '<App/>'
})
